//
//  IWTitleButton.m
//  WeiBo17
//
//  Created by teacher on 15/8/16.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "IWTitleButton.h"

//文字与title之前的间距
#define MARGIN 5

@implementation IWTitleButton



- (void)layoutSubviews{
    [super layoutSubviews];
    
    //先调整titleLabel的x为0
    
    self.titleLabel.x = 0;
    
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame) + MARGIN;
    
    self.width = self.titleLabel.width + self.imageView.width + MARGIN;
    self.centerX = self.superview.width * 0.5;
}


- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    [super setTitle:title forState:state];
    [self sizeToFit];
}

- (void)setImage:(UIImage *)image forState:(UIControlState)state{
    [super setImage:image forState:state];
    [self sizeToFit];
}



@end
